package com.hlkj.warboot.configurer.util;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Description:
 * @Author: lixing
 * @Date: 2019/7/20 12:57
 */
public class UserAgentUtil {
    /*
     * @Description 判断移动端/PC端
     * @Author lixing
     * @Date 2019/7/20 12:58
     * @Param [request] 
     * @return boolean
     */
    public static boolean isMobile(HttpServletRequest request) {
        List<String> mobileAgents = Arrays.asList("ipad", "iphone os", "rv:1.2.3.4", "ucweb", "android", "windows ce", "windows mobile");
        String ua = request.getHeader("User-Agent").toLowerCase();
        for (String sua : mobileAgents) {
            if (ua.contains(sua)) {
                return true;//手机端
            }
        }
        return false;//PC端
    }

    /*
     * @Description 是否微信浏览器
     * @Author lixing
     * @Date 2019/7/20 12:58
     * @Param [request] 
     * @return boolean
     */
    public static boolean isWechat(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent").toLowerCase();
        return ua.contains("micromessenger");//微信
        //非微信手机浏览器
    }
}
